/**
 * [金额转换]
 * @Author: Fu Xiaochun
 * @Email:  fuzhengchun@ling1.org
 */
import config from '@/config/env.js';
const priceRideo = config.PRICE_RADIUS;

//系统单位金额转换成人民币元
export const sysToYuan = (price, float =2) => {
	float = parseInt(float);
    price = price / priceRideo;
    let priceStr = price.toString();
    let dotIndex = priceStr.indexOf('.');
    let rightPad = new Array(float+1).join('0');

    if(dotIndex < 0){
        return price.toFixed(float);
    }else{
        if(float < 1){
            return (priceStr + rightPad).substring(0, dotIndex);
        }else{
            return (priceStr + rightPad).substring(0, dotIndex + 1 + float);
        }
    }
};

// 人民币元转换成系统单位金额
export const yuanToSys = (m) => {
    let money = parseFloat(m);
    money = isNaN(money) ? 0 : money;
    return money * priceRideo;
}
